﻿using System;
using System.Web.UI.WebControls;
using Core.Library;
using DataObject.Online;

namespace CMS.Controls.Online
{
    public partial class OnlineManager : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ListData();
            }
        }

        private void ListData()
        {
            lvList.DataSource = OnlineController.Online_GetByTypeId(0);
            lvList.DataBind();
        }

        protected void Create(object sender, EventArgs e)
        {
            Response.Redirect(UrlHelpers.CreateOnline);
        }

        protected void lvList_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            var dataItem = (ListViewDataItem)e.Item;
            var id = ConvertUtility.ToInt32(lvList.DataKeys[dataItem.DisplayIndex].Value);

            if (id > 0)
            {
                if (string.Equals(e.CommandName, "DeleteOnline"))
                {
                    OnlineController.Online_Delete(id);
                    ltMessage.Text = MessageUtility.ShowMessage(string.Empty, "Xóa dữ liệu thành công", MessageType.Success);
                    ListData();
                }
            }
        }
    }
}